<?php
/* Deatils of Coach */
error_reporting(0);
include "general_include.php";
//include "checklogin.php";
$page_name=basename($_SERVER['SCRIPT_FILENAME']);
#########################################################################

   unset($_SESSION['sql']);
   unset($_SESSION['sqlOrder']);
   unset($_SESSION['sqlPart']);
   unset($_SESSION['sort']);

//############## 
if($_SESSION['replay_game_id']!='')
    $game_id = $_SESSION['replay_game_id'];
if(isset($_REQUEST['game_id']))
{ 
	$_SESSION['replay_game_id'] = $_REQUEST['game_id'];
    $game_id = $_SESSION['replay_game_id'];
}
//#############

//$game_id=$_REQUEST['game_id'];
$order_id=$_REQUEST['order_id'];
$action=$_REQUEST['action'];
$coach_id=$_REQUEST['coach_id'];
$dosearch=$_REQUEST['dosearch'];

$ladder_id = array();
$race_id = array();
$champion_id = array();
$class_id = array();
$map_id = array();
$mode_id = array();
$team_id = array();
$type_id = array();
$versus_id = array();

$server_id = $_REQUEST['server_id'];
$rating_id = $_REQUEST['rating_id'];
$availability = $_REQUEST['availability'];
$language_id = $_REQUEST['language_id'];

$duration = $_REQUEST['duration'];
if($duration == '')
  $duration = '0;60';
if(!empty($duration))
{
   $duration_range = explode(";",$duration);
   $min_duration = $duration_range[0];
   $max_duration = $duration_range[1];
   if($min_duration == '0' && $max_duration == '60')
    $sqlPart .='';
   else if($min_duration == '0' && $max_duration <60)
    $sqlPart .=" AND time_length <='$max_duration'";
   else if($min_duration >'0' && $max_duration == '60')
    $sqlPart .=" AND time_length >='$min_duration'";
   else 
     $sqlPart .=" AND time_length BETWEEN '$min_duration' AND '$max_duration'";		  
}   

$action_arr=array("list_order","list_search","list_paginate","review_post");
if(in_array($action,$action_arr))
{
	$IsProcess = 'Y';
	$smarty->assign('IsProcess',"Y");
	
}
if($IsProcess <> 'Y')
	 include "top.php";


if($game_id=='')
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE is_default='Y'";
else
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE game_id='$game_id'";  

$gamerow = $UserManagerObjAjax->GetRecords("Row",$GameSql);
$game_id=$gamerow['game_id'];
$game_name=$gamerow['game_name'];

function findvalue($table,$fld_name,$fld_value,$find_value)
	{
		 if($fld_value=='')
				return false;
				
			$SelectTypeSql = "SELECT ".$find_value." FROM ".$table." WHERE $fld_name=".$fld_value;
			$SelectType = mysql_fetch_array(mysql_query($SelectTypeSql));
			return $SelectType[0];
	}	
/*$record_per_page = !empty($record_per_page)?$record_per_page:15;
$paginationObj = new PaginationClassFrontAjax($record_per_page,3,1,'Next','Previous');*/

  if($dosearch=='GO')
  {
    $SLink = '';

	if(!empty($is_versus))
	{
	   $searchSql =  $searchSql." AND is_versus='Y' and ( versus='R' or versus='B' )";
	   $SLink.="&is_versus=Y&versus=R";
	} 
	if(!empty($is_race))
	{
	   $searchSql =  $searchSql." AND is_race='Y' and ( race='R' or race='B' )";
	   $SLink.="&is_race=Y&race=R";
	} 

	if(!empty($is_ladder))
	{
	   $searchSql =  $searchSql." AND is_ladder='Y' and ( ladder='R' or ladder='B' )";
	   $SLink.="&is_ladder=Y&ladder=R";
	} 

	if(!empty($is_champion))
	{
	   $searchSql =  $searchSql." AND is_champion='Y' and ( champion='R' or champion='B' )";
	   $SLink.="&is_champion=Y&champion=R";
	} 
	if(!empty($is_class))
	{
	   $searchSql =  $searchSql." AND is_class='Y' and ( class='R' or class='B' )";
	   $SLink.="&is_class=Y&class=R";
	} 
	if(!empty($is_map))
	{
	   $searchSql =  $searchSql." AND is_map='Y' and ( map='R' or map='B' )";
	   $SLink.="&is_map=Y&map=R";
	}

	$SearchLink="dosearch=GO".$SLink;
  } 





############################################################################




$IsPreserved	= 'Y';
$IsProcess		= $_REQUEST['IsProcess'];

$ip_address = $_SERVER['REMOTE_ADDR'];


$RatingCatSql="SELECT rating_category,rcat_id FROM ".TABLEPREFIX."_rating_category WHERE rating_type='V' ORDER BY rating_order";
$RatingCatDetails=$UserManagerObjAjax->GetRecords("All",$RatingCatSql);

$NumRatingCat=count($RatingCatDetails);

for($i=0;$i<$NumRatingCat;$i++){
$RatingCatArr[$i]['rcat_id']=$RatingCatDetails[$i]['rcat_id'];
$RatingCatArr[$i]['rating_category']=$RatingCatDetails[$i]['rating_category'];
}

if($game_id=='')
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE is_default='Y'";
else
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE game_id='$game_id'";  

$gamerow = $UserManagerObjAjax->GetRecords("Row",$GameSql);
$game_id=$gamerow['game_id'];
$game_name=$gamerow['game_name'];
$logged_user=$_SESSION['user_id'];


$item_per_page=$_SESSION['item_per_page'] = $_REQUEST['item_per_page'];
	if(empty($item_per_page) || !isset($item_per_page))
	{
	$item_per_page=10;
	} 

$action	= $_REQUEST['action'];
$video_id = $_REQUEST['video_id']; 

$countSql = "SELECT * FROM ".TABLEPREFIX."_video_view_count WHERE ip_address='$ip_address' AND view_date=CURDATE() AND video_id='$video_id'";
$countArr = $UserManagerObjAjax->GetRecords("Row",$countSql);
if($countArr['video_id']=='')
{
  $adCount = "INSERT INTO ".TABLEPREFIX."_video_view_count SET ip_address='$ip_address',view_date=CURDATE(),video_id='$video_id'";
  $UserManagerObjAjax->Execute($adCount);
}
if($action == 'review_post')
{
  	$review_comment = $_POST['review_comment'];
	$reviewed_by=$_POST['reviewed_by'];
	$total_rating=0;
	

	$VideoReviewSql="INSERT INTO ".TABLEPREFIX."_video_review set video_id='$video_id',reviewed_by='$reviewed_by',review_comment='$review_comment',is_active='Y',
	date_added='".date('Y-m-d')."'";
	$VideoReview= $UserManagerObjAjax->Execute($VideoReviewSql);

}


/*if($action == 'make_fav')
{
  $video_id=$_REQUEST['video_id'];
  $add_fav = "INSERT INTO ".TABLEPREFIX."_user_fav_video SET user_id='".$_SESSION['user_id']."',video_id='$video_id',date_added='".date('Y-m-d')."'";
  $UserManagerObjAjax->Execute($add_fav);
}
if($action == "del_fav")
    {	
	  $fav_video_id=$_REQUEST['fav_video_id'];
	  $DelSql = "DELETE FROM ".TABLEPREFIX."_user_fav_video where fav_video_id='$fav_video_id'";
	  $UserManagerObjAjax->Execute($DelSql);
   }  */
// Fetching video details 
 $VideoSql="SELECT *,DATE_FORMAT(date_added,'%M %d , %Y') as v_dt FROM ".TABLEPREFIX."_video where video_id='$video_id'";
 $VideoArr=$UserManagerObjAjax->GetRecords("Row",$VideoSql);
 
 $VideoArr['like']='N';
 
 $LikeSql = "SELECT count(*) AS numlike FROM ".TABLEPREFIX."_user_like WHERE video_id=".$video_id ;
		$LikeArr = $UserManagerObjAjax->GetRecords('Row',$LikeSql);
		
	$VideoArr['numlike']=$LikeArr['numlike'];
	
	$LikeDoSql = "SELECT * FROM ".TABLEPREFIX."_user_like WHERE user_id=".$VideoArr['user_id']." AND user_type_id=".$_SESSION['user_type']." 
					AND selected_by=".$_SESSION['user_id']." AND video_id=".$VideoArr['video_id'] ;
		$LikeDoArr = $UserManagerObjAjax->GetRecords('Row',$LikeDoSql);
		if(count($LikeDoArr)>0) $VideoArr['like']='Y';
		
		

$userSql = "SELECT name FROM ".TABLEPREFIX."_user WHERE user_id='".$VideoArr['user_id']."'";
$userArr = $UserManagerObjAjax->GetRecords("Row",$userSql);

$VideoArr['name']=$userArr['name'];
$VideoArr['description']=stripslashes($VideoArr['description']);
for($x=1;$x<=$VideoArr['overall_rating'];$x++)
	{
	  $totstar.="<img src='images/star-c.gif' alt='' border='0' />";
	}
	$istar=5 - $VideoArr['overall_rating']; 
	for($y=1;$y<=$istar;$y++)
	{
	  $totstar.="<img src='images/star-g.gif' alt='' border='0' />";
	}
$VideoArr['star']=$totstar;
if($VideoArr['is_video_url'] == 'Y')
  {
    $link = explode ('v=',$VideoArr['video_url']);
	$video_num = $link[1];
  }

$VideoArr['game']= findvalue(TABLEPREFIX."_game","game_id",$VideoArr['game_id'],"game_name");
//$VideoArr['ladder']= findvalue(TABLEPREFIX."_game_ladder","ladder_id",$VideoArr['ladder_id'],"ladder_name");
$Videoladder = explode(",",$VideoArr['ladder_id']);
	$ladder='';
	for($i=0;$i<count($Videoladder);$i++)
	{
	  if($Videoladder[$i]<>'')
	    $ladder .= findvalue(TABLEPREFIX."_game_ladder","ladder_id",$Videoladder[$i],"ladder_name").' , ';
	} 

$VideoArr['ladder']= substr($ladder,0,-2);	
$Videoversus = explode(",",$VideoArr['versus_id']);
	$versus='';
	for($i=0;$i<count($Videoversus);$i++)
	{
	  if($Videoversus[$i]<>'')
	    $ladder .= findvalue(TABLEPREFIX."_game_versus","versus_id",$Videoversus[$i],"versus_title").' , ';
	} 
$VideoArr['versus']= substr($versus,0,-2);	
$Videotype = explode(",",$VideoArr['type_id']);
	$type='';
	for($i=0;$i<count($Videotyoe);$i++)
	{
	  if($Videotype[$i]<>'')
	    $ladder .= findvalue(TABLEPREFIX."_game_type","type_id",$Videotype[$i],"type_title").' , ';
	} 
$VideoArr['type']= substr($type,0,-2);	
$Videoteam = explode(",",$VideoArr['team_id']);
	$team='';
	for($i=0;$i<count($Videoteam);$i++)
	{
	  if($Videoteam[$i]<>'')
	    $team .= findvalue(TABLEPREFIX."_game_team","team_id",$Videoteam[$i],"team_title").' , ';
	} 
$VideoArr['team']= substr($team,0,-2);	
$Videochampion = explode(",",$VideoArr['champion_id']);
	$champion='';
	for($i=0;$i<count($Videochampion);$i++)
	{
	  if($Videochampion[$i]<>'')
	    $champion .= findvalue(TABLEPREFIX."_game_champion","champion_id",$Videochampion[$i],"champion_title").' , ';
	} 
$VideoArr['champion']= substr($champion,0,-2);	
$Videomap = explode(",",$VideoArr['map_id']);
	$map='';
	for($i=0;$i<count($Videomap);$i++)
	{
	  if($Videomap[$i]<>'')
	    $map .= findvalue(TABLEPREFIX."_game_map","map_id",$Videomap[$i],"map_title").' , ';
	} 
$VideoArr['map']= substr($map,0,-2);
$Videomode = explode(",",$VideoArr['mode_id']);
	$mode='';
	for($i=0;$i<count($Videomode);$i++)
	{
	  if($Videomode[$i]<>'')
	    $mode .= findvalue(TABLEPREFIX."_game_mode","mode_id",$Videomode[$i],"mode_title").' , ';
	} 
$VideoArr['mode']= substr($mode,0,-2);		
$Videoclass = explode(",",$VideoArr['class_id']);
	$class='';
	for($i=0;$i<count($Videoclass);$i++)
	{
	  if($Videoclass[$i]<>'')
	    $class .= findvalue(TABLEPREFIX."_game_class","class_id",$Videoclass[$i],"class_title").' , ';
	} 
$VideoArr['class']= substr($class,0,-2);	
$dateSql = "SELECT date_format('".$VideoArr['date_added']."','%M  %d , %Y') as video_date";
$DateArr = $UserManagerObjAjax->GetRecords("Row",$dateSql);
$VideoArr['video_date']=$DateArr['video_date'];
// End Video details

// Start fetching video review

 $Reviews = "SELECT * FROM ".TABLEPREFIX."_video_review WHERE video_id='$video_id' and is_active='Y' ORDER BY date_added DESC";

 $PaginationObjAjaxLatest=new PaginationClassAjax($item_per_page,"prev",'',"next","active",$adodbcon);
 $pagination_arr = $PaginationObjAjaxLatest->PaginationAjax($Reviews,$page_name."?video_id=".$video_id."&action=".$action."&item_per_page=".$item_per_page,"Managergeneral");
 
	/* pagination ends */
	
 $VdoReview = $UserManagerObjAjax->GetRecords("All",$pagination_arr[0]);
 
 
 $NumReview = count($VdoReview);
 
 for($r=0;$r<$NumReview;$r++)
 {
    $VdoReview[$r]['review_by'] = findvalue(TABLEPREFIX."_user","user_id",$VdoReview[$r]['reviewed_by'],"name");
	
    $RdateSql = "SELECT date_format('".$VdoReview[$r]['date_added']."','%M  %d , %Y at %h %p') as review_date";
	$RdateArr = $UserManagerObjAjax->GetRecords("Row",$RdateSql);
	$VdoReview[$r]['r_date'] = $RdateArr['review_date'];

		
	$userImg = "SELECT photo FROM ".TABLEPREFIX."_user WHERE user_id='".$VdoReview[$r]['reviewed_by']."'";
	$ImgArr = $UserManagerObjAjax->GetRecords("Row",$userImg);
	$VdoReview[$r]['photo'] = $ImgArr[0];	
	
	$Usertype = "SELECT user_type_id FROM ".TABLEPREFIX."_user_type_user_relation WHERE user_id='".$VdoReview[$r]['reviewed_by']."'";
	$typeArr = $UserManagerObjAjax->GetRecords("All",$Usertype);
	for($t=0;$t<count($typeArr);$t++)
	{
	  if($typeArr[$t][0] == 1)
	     $coach = 1;
	  if($typeArr[$t][0] == 3)
	     $partner = 1;	 
	}
	//$VdoReview[$r]['userType'] = $TypeArr[0];	
	if($coach == '1')
	{
	  $VdoReview[$r]['userlink'] = "coachdetails.php?coach_id=".$VdoReview[$r]['reviewed_by'];
	  if($VdoReview[$r]['photo'] == '')
	    $img = 'images/coach_thumb.jpg';
	  else
	  	$img = 'uploaded/user_images/thumbs/mid_'.$VdoReview[$r]['photo'];
	}  
	else if($partner == 1)
	{
	  $VdoReview[$r]['userlink'] = "studentdetails.php?student_id=".$VdoReview[$r]['reviewed_by']; 
	  if($VdoReview[$r]['photo'] == '')
	    $img = 'images/student_thumb.jpg';
	  else
	  	$img = 'uploaded/user_images/thumbs/mid_'.$VdoReview[$r]['photo'];
	} 
	else
	{
	  $VdoReview[$r]['userlink'] = "#"; 
	  if($VdoReview[$r]['photo'] == '')
	    $img = 'images/student_thumb.jpg';
	  else
	  	$img = 'uploaded/user_images/thumbs/mid_'.$VdoReview[$r]['photo'];
	
	} 
	  $VdoReview[$r]['img'] = $img;
 }
 

// End fetching video review

// likes and dislikes start

$LikeSql = "SELECT count(*) AS numlike FROM ".TABLEPREFIX."_user_like WHERE selected_for='L' AND video_id=".$video_id ;
$LikeArr = $UserManagerObjAjax->GetRecords('Row',$LikeSql);
		
$UnlikeSql = "SELECT count(*) AS numunlike FROM ".TABLEPREFIX."_user_like WHERE selected_for='D' AND video_id=".$video_id ;
$UnlikeArr = $UserManagerObjAjax->GetRecords('Row',$UnlikeSql);
		
$RatingLike=$LikeArr['numlike'];
$RatingUnlike=$UnlikeArr['numunlike'];

$TotalRating=$RatingLike+$RatingUnlike;

$RatingAvgLike=($RatingLike*100)/$TotalRating;
$RatingAvgUnlike=($RatingUnlike*100)/$TotalRating;

$WidthGreen=(210*$RatingAvgLike)/100;
$WidthRed=(210*$RatingAvgUnlike)/100;

// likes and dislikes end

// Selecting favourite video
if($_SESSION['user_type'] == '2')
{
   $q_fav = "SELECT * FROM ".TABLEPREFIX."_user_fav_video WHERE user_id='".$_SESSION['user_id']."' AND video_id='$video_id'";
   $FavArr = $UserManagerObjAjax->GetRecords("Row",$q_fav);
   if($FavArr['fav_video_id'] >0)
     $is_fav = 1;
   else 
     $is_fav=0;	 
}

// Selecting related videos 
  $RelvdoSql = "(SELECT * FROM ".TABLEPREFIX."_video WHERE user_id=".$VideoArr['user_id']." AND game_id=".$VideoArr['game_id']." AND video_id!='$video_id'
  ORDER BY date_added DESC) UNION (SELECT * FROM ".TABLEPREFIX."_video WHERE user_id!=".$VideoArr['user_id']." AND game_id=".$VideoArr['game_id']." ORDER BY date_added DESC)";
  $RelvdoRow = $UserManagerObjAjax->GetRecords("All",$RelvdoSql);
   $NumRelvdo = count($RelvdoRow);
    for($a=0;$a<$NumRelvdo;$a++)
	{
		
		$RelvdoRow[$a]['user'] = findvalue(TABLEPREFIX."_user","user_id",$RelvdoRow[$a]['user_id'],"name");
		$viewCount = "SELECT count(*) FROM ".TABLEPREFIX."_video_view_count WHERE video_id =".$RelvdoRow[$a]['video_id'];
		$viewArr = $UserManagerObjAjax->GetRecords("Row",$viewCount);
		$RelvdoRow[$a]['view_count'] = $viewArr[0];
		
	}
#########################################################################################################################

$gameSql = "SELECT game_id,game_name FROM ".TABLEPREFIX."_game where is_active='Y' ORDER BY game_name";
$GameArr = $UserManagerObjAjax->HtmlOptionArrayCreate($gameSql);

$replaySql="SELECT * FROM ".TABLEPREFIX."_video WHERE game_id='$game_id'".$searchSql.$sqlPart;

/* find the ladder of selected game */

if($gamerow['is_ladder']=='Y' and ( $gamerow['ladder']=='R' or $gamerow['ladder']=='B' ) )
{
	$is_ladder = 'Y';
	$Selectladder="SELECT * FROM ".TABLEPREFIX."_game_ladder WHERE game_id='$game_id' and is_active='Y' order by ladder_order";
	$LadderArr=$UserManagerObjAjax->GetRecords("All",$Selectladder);
	$Numladder=count($LadderArr);
	for($gl=0;$gl<$Numladder;$gl++)
	{
		$query=$replaySql." and ladder_id=".$LadderArr[$gl]['ladder_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$LadderArr[$gl]['countrow']=count($replayCount); 
	}
}

/* find the race of selected game */
if( $gamerow['is_race']=='Y' and ( $gamerow['race']=='R' or $gamerow['race']=='B' ) )
{
	$is_race = 'Y';
	$Selectrace="SELECT * FROM ".TABLEPREFIX."_game_race WHERE game_id='$game_id' and is_active='Y'";
	$RaceArr=$UserManagerObjAjax->GetRecords("All",$Selectrace);
	$Numrace=count($RaceArr);
	for($gr=0;$gr<$Numrace;$gr++)
	{
		$query=$replaySql." and race_id=".$RaceArr[$gr]['race_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$RaceArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Champion of selected game */
if( $gamerow['is_champion']=='Y' and ( $gamerow['champion']=='R' or $gamerow['champion']=='B' ) )
{
	$is_champion = 'Y';
	$SelectChampion="SELECT * FROM ".TABLEPREFIX."_game_champion WHERE game_id='$game_id' and is_active='Y'";
	$ChampionArr=$UserManagerObjAjax->GetRecords("All",$SelectChampion);
	$NumChampion=count($ChampionArr);
	for($gr=0;$gr<$NumChampion;$gr++)
	{
		$query=$replaySql." and champion_id=".$ChampionArr[$gr]['champion_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$ChampionArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Class of selected game */
if( $gamerow['is_class']=='Y' and ( $gamerow['class']=='R' or $gamerow['class']=='B' ) )
{
	$is_class = 'Y';
	$SelectClass="SELECT * FROM ".TABLEPREFIX."_game_class WHERE game_id='$game_id' and is_active='Y'";
	$ClassArr=$UserManagerObjAjax->GetRecords("All",$SelectClass);
	$NumClass=count($ClassArr);
	for($gr=0;$gr<$NumClass;$gr++)
	{
		$query=$replaySql." and class_id=".$ClassArr[$gr]['class_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$ClassArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Map of selected game */
if( $gamerow['is_map']=='Y' and ( $gamerow['map']=='R' or $gamerow['map']=='B' ) )
{
	$is_map = 'Y';
	$SelectMap="SELECT * FROM ".TABLEPREFIX."_game_map WHERE game_id='$game_id' and is_active='Y'";
	$MapArr=$UserManagerObjAjax->GetRecords("All",$SelectMap);
	$NumMap=count($MapArr);
	for($gr=0;$gr<$NumMap;$gr++)
	{
		$query=$replaySql." and map_id=".$MapArr[$gr]['map_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$MapArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Mode of selected game */
if( $gamerow['is_mode']=='Y' and ( $gamerow['mode']=='R' or $gamerow['mode']=='B' ) )
{
	$is_mode = 'Y';
	$SelectMode="SELECT * FROM ".TABLEPREFIX."_game_mode WHERE game_id='$game_id' and is_active='Y'";
	$ModeArr=$UserManagerObjAjax->GetRecords("All",$SelectMode);
	$NumMode=count($ModeArr);
	for($gr=0;$gr<$NumMode;$gr++)
	{
		$query=$replaySql." and mode_id=".$ModeArr[$gr]['mode_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$ModeArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Team of selected game */
if( $gamerow['is_team']=='Y' and ( $gamerow['team']=='R' or $gamerow['team']=='B' ) )
{
	$is_team = 'Y';
	$SelectTeam="SELECT * FROM ".TABLEPREFIX."_game_team WHERE game_id='$game_id' and is_active='Y'";
	$TeamArr=$UserManagerObjAjax->GetRecords("All",$SelectTeam);
	$NumTeam=count($TeamArr);
	for($gr=0;$gr<$NumTeam;$gr++)
	{
		$query=$replaySql." and team_id=".$TeamArr[$gr]['team_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$TeamArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Type of selected game */
if( $gamerow['is_type']=='Y' and ( $gamerow['type']=='R' or $gamerow['type']=='B' ) )
{
	$is_type = 'Y';
	$SelectType="SELECT * FROM ".TABLEPREFIX."_game_type WHERE game_id='$game_id' and is_active='Y'";
	$TypeArr=$UserManagerObjAjax->GetRecords("All",$SelectType);
	$NumType=count($TypeArr);
	for($gr=0;$gr<$NumType;$gr++)
	{
		$query=$replaySql." and type_id=".$TypeArr[$gr]['type_id'];
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$TypeArr[$gr]['countrow']=count($replayCount); 
	}
}

/* find the Versus of selected game */
if( $gamerow['is_versus']=='Y' and ( $gamerow['versus']=='R' or $gamerow['versus']=='B' ) )
{
	$is_versus = 'Y';
	$SelectVersus="SELECT * FROM ".TABLEPREFIX."_game_versus WHERE game_id='$game_id' and is_active='Y'";
	$VersusArr=$UserManagerObjAjax->GetRecords("All",$SelectVersus);
	$NumVersus=count($VersusArr);
	for($gr=0;$gr<$NumVersus;$gr++)
	{
		$query=$replaySql." and FIND_IN_SET(".$VersusArr[$gr]['versus_id'].",versus_id)";
		$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
		$VersusArr[$gr]['countrow']=count($replayCount); 
	}
}
/* for star rating */
for($s=1,$m=0;$s<=5;$s++) 
{
    $query=$replaySql." and overall_rating=".$s;
	$replayCount=$UserManagerObjAjax->GetRecords("All",$query); 
	
	if(count($replayCount)>0)
	{
	  $StarArr[$m]['countrow']=count($replayCount);
	  $StarArr[$m]['star']=$s;
	  $m++;
	}  
	
}



###########################################################################################################################

$smarty->assign('IsProcess',$IsProcess);
$smarty->assign('NumReview',$NumReview);
$smarty->assign('VdoReview',$VdoReview);
$smarty->assign('RelvdoRow',$RelvdoRow);
$smarty->assign('is_fav',$is_fav);
$smarty->assign('fav_id',$FavArr['fav_video_id']);
$smarty->assign('video_num',$video_num);
$smarty->assign('video_id',$video_id);
$smarty->assign('VideoArr',$VideoArr);
$smarty->assign('pagination_arr',$pagination_arr);
$smarty->assign('page_name',$page_name);
$smarty->assign('pg_name',$page_name);
$smarty->assign('NumRatingCat',$NumRatingCat);
$smarty->assign('RatingCatArr',$RatingCatArr);
$smarty->assign('logged_user',$logged_user);


###########################################################################################################################

$smarty->register_modifier('in_array', 'in_array');
$smarty->assign('StarArr',$StarArr);
$smarty->assign('SearchLink',$SearchLink);
$smarty->assign('SLink',$SLink);

$smarty->assign("GameArr",$GameArr);
$smarty->assign('game_id',$game_id);
$smarty->assign('coach_id',$coach_id);
$smarty->assign('game_name',$game_name);
$smarty->assign('coachArr',$coachArr);
$smarty->assign("NumReplay",$NumReplay);
$smarty->assign("totRec",$totRec);
$smarty->assign('duration',$duration);

$smarty->assign('Numladder',$Numladder);
$smarty->assign('LadderArr',$LadderArr);
$smarty->assign('Numrace',$Numrace);
$smarty->assign('RaceArr',$RaceArr);
$smarty->assign('NumChampion',$NumChampion);
$smarty->assign('ChampionArr',$ChampionArr);
$smarty->assign('NumClass',$NumClass);
$smarty->assign('ClassArr',$ClassArr);
$smarty->assign('NumMap',$NumMap);
$smarty->assign('MapArr',$MapArr);
$smarty->assign('NumMode',$NumMode);
$smarty->assign('ModeArr',$ModeArr);
$smarty->assign('NumTeam',$NumTeam);
$smarty->assign('TeamArr',$TeamArr);
$smarty->assign('NumType',$NumType);
$smarty->assign('TypeArr',$TypeArr);
$smarty->assign('NumVersus',$NumVersus);
$smarty->assign('VersusArr',$VersusArr);
$smarty->assign('RatingAvgLike',$RatingAvgLike);
$smarty->assign('RatingAvgUnlike',$RatingAvgUnlike);
$smarty->assign('RatingLike',$RatingLike);
$smarty->assign('RatingUnlike',$RatingUnlike);
$smarty->assign('WidthGreen',$WidthGreen);
$smarty->assign('WidthRed',$WidthRed);
$FromPage='videodetails';
$smarty->assign('FromPage',$FromPage);
###########################################################################################################################
if($IsProcess <> 'Y')
{
	//include "top.php";
	 include "replays_leftpanel.php";
    
}
	
$smarty->display('videodetails.tpl');
if($IsProcess <> 'Y')
{
     include "replays_rightpanel.php";
	 include "footer.php";
}	 
?>